import { TableColumnComponent } from './table-column.component';
import { Component,OnInit, Input } from '@angular/core';
import { WidthItem } from '../table.interface';
import { ElTableFormat } from '../utils/format';

@Component({
  selector: 'el-table-header',
  templateUrl: './table-header.component.html',
})
export class TableHeaderComponent implements OnInit {
    el:any;
    @Input() model:any = [];
    @Input() fixed:string = '';
    @Input() layout: any;
    @Input() border: boolean=false;
    @Input() height: string | number='';
    @Input() center: boolean=false;
    @Input() columnsWidth!:WidthItem[];
  constructor(el:TableColumnComponent) {
      this.el = el;
  }

  ngOnInit(): void {
    
  }

  handleHeaderClick(event:any,tr:any){
    const target = event.target;
    let cell = target.tagName === 'TH' ? target : target.parentNode;
    if(ElTableFormat.hasClass(cell, 'noclick')) return;
    cell = cell.querySelector('.el-table__column-filter-trigger') || cell;
    console.log(cell,tr);
    //   const table = this.$parent;

    //   let filterPanel = this.filterPanels[column.id];

    //   if (filterPanel && column.filterOpened) {
    //     filterPanel.showPopper = false;
    //     return;
    //   }

    //   if (!filterPanel) {
    //     filterPanel = new Vue(FilterPanel);
    //     this.filterPanels[column.id] = filterPanel;
    //     if (column.filterPlacement) {
    //       filterPanel.placement = column.filterPlacement;
    //     }
    //     filterPanel.table = table;
    //     filterPanel.cell = cell;
    //     filterPanel.column = column;
    //     !this.$isServer && filterPanel.$mount(document.createElement('div'));
    //   }

    //   setTimeout(() => {
    //     filterPanel.showPopper = true;
    //   }, 16);
    // console.log(event,event.target,event.stopPropagation())
  }
  makeClasses(th:any){
    var /** @type {?} */ isLeaf = this.getColspan(th) > 1 ? '' : 'is-leaf';
    return this.height === 'auto' ? isLeaf + " " : ' gutter';
  }

  getRowspan(td:any){
    if (td.deep === 0 && td.level !== 0) {
        return td.level + 1;
    }
    return 1;
  }
  

  getColspan(th:any){
    return th.childCount > 0 ? th.childCount : 1;
  }

}
